package program;

import java.sql.Time;
import java.util.*;

public class TTEntry {

	private Train train;
	private Track track;
	
	private boolean direction;
	private Date departTime;
	private Date arrivalTime;
	
	public TTEntry(Train _train, Track _track, boolean _directionAtoB, Date _departTime) {
		
		if (_train == null || _track == null || _departTime == null) throw new IllegalArgumentException("Cannot have null parameter");
		
		train = _train;
        track = _track;
        
        //If set to true this means we are travelling from stationA to stationB in track, false visa versa
        direction = _directionAtoB;
     
        departTime = _departTime;
        arrivalTime = calcArrivalTime(track, departTime);
        
	}
	
	//calculates the arrival time of an entry, based on the departure time and the average time travelled on a track
	private Date calcArrivalTime(Track track, Date departTime){
		long aveTime = track.getaveTravelTime()*60000;			//converts minutes to milliseconds
		Date toReturn = new Date();
		toReturn.setTime(departTime.getTime() + aveTime);
		return toReturn;
	}
	
	public void setDepartTime(Date time){
		departTime = time;
	}
        
    public Track getTrack(){
        return track;
    }
    
    public boolean getDirection(){
        return direction;
    }
    
    public Date getDepartureTime(){
        return departTime;
    }
    
    public Date getArrivalTime(){
        return arrivalTime;
    }
	
}
